package org.tang.stock;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;

public class MA_5 {

	public static void main(String[] args) throws Exception {
		FileReader syzg = new FileReader(new File("D:\\table.csv"));
		BufferedReader buffer = new BufferedReader(syzg);
		ArrayList<Stock> stocks = new ArrayList<Stock>();
		String line = null;
		line = buffer.readLine();
		while ((line = buffer.readLine()) != null) {
			Stock tmp = new Stock(line);
			if (tmp.getVolume() != 0)
				stocks.add(tmp);
		}
		System.out.println("" + stocks.size());
		int sum1 = 0;
		int sum2 = 0;
		double t = 0.0;
		int count = 0,count3 =0;
		for (int i = 1; i < stocks.size() - 10; i++) {
			sum1 = sum2 ;
			for (int j = 0; j < 10; j++) {
				sum1 += stocks.get(i + j).getClosePrice();
				sum2 += stocks.get(i + j + 1).getClosePrice();
			}
			double or= stocks.get(i).getClosePrice();
			if (sum1 > sum2 ) {// && sum2*1.0f >= sum3*1.005f){
				count++;
				if(or*1.013 < stocks.get(i-1).getOpenPrice())
					t += stocks.get(i-1).getOpenPrice()*1.0/or -1.003;
				else if(or*1.013 < stocks.get(i-1).getHightPrice())
					t += 0.01;
				else 
					t += stocks.get(i-1).getClosePrice()*1.0/or - 1.003;
			}
		}
		System.out.println("t = " + t);
		System.out.println("count = " + count + ",count3 = " + count3 + " % = " + count3*1.0/count);
	}
}
